from django.contrib import admin
from booktest.models import *
# Register your models here.

# 内联在书籍下的
class HeroInfoInline(admin.StackedInline):
    extra = 0
    model = HeroInfo


class HeroInfoAdmin(admin.ModelAdmin):
    # 模糊搜索的功能
    search_fields = ('name', 'content')
    #列表页展示字段
    list_display = ['id','name','content','gender','book']
    #详情页展示字段设置
    fieldsets = (
        ['主要参数', {
            'fields': ('name','content','gender'),
        }],
        ['书籍', {
            'classes': ('collapse',),  # CSS
            'fields': ('book',),
        }])


class BookInfoAdmin(admin.ModelAdmin):

    inlines = [HeroInfoInline]
    list_display = ['id','title','pub_date']  #列表展示列
    list_display_links = ('id','pub_date') #点击列可以跳转到详情
    list_editable = ('title',)

    # 定制Action行为具体方法
    def func(self, request, queryset):
        print(self, request, queryset)
        print(request.POST.getlist('_selected_action'))



    func.short_description = "中文显示自定义Actions"
    actions = [func, ]
    # Action选项都是在页面上方显示
    actions_on_top = True
    # Action选项都是在页面下方显示
    actions_on_bottom = False

    # 是否显示选择个数
    actions_selection_counter = True

    fields = ('title',)   #详情展示字段



admin.site.register(BookInfo,BookInfoAdmin)
admin.site.register(HeroInfo,HeroInfoAdmin)